package com.hejr.springboot2_003.controller;

import com.hejr.springboot2_003.common.CommonResultObject;
import com.hejr.springboot2_003.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * User控制层
 */
@RestController
public class UserController {

    @Autowired
    private IUserService userService;


    /**
     * 新增用户
     *
     * @param userName
     * @return
     */
    @RequestMapping("/addUser")
    public Object addUser(String userName) {
        CommonResultObject resultObject = new CommonResultObject();
        try {
            resultObject.setResult(userService.addUser(userName));
            resultObject.setCode(200);
            resultObject.setMessage("新增用户成功...");
        } catch (Exception e) {
            resultObject.setCode(1);
            resultObject.setMessage("新增用户失败...");
            e.printStackTrace();
        }
        return resultObject;
    }

    @RequestMapping("/findUserList")
    public Object findUserList(Integer pageNo, Integer pageSize) {
        CommonResultObject resultObject = new CommonResultObject();
        try {
            resultObject.setResult(userService.findUserList(pageNo, pageSize));
            resultObject.setCode(200);
            resultObject.setMessage("获取用户列表成功...");
        } catch (Exception e) {
            resultObject.setCode(1);
            resultObject.setMessage("获取用户列表失败..." + e.getMessage());
            e.printStackTrace();
        }
        return resultObject;
    }
}